/*
 * Copyright (C) 2011 Urals State University,
 * Department of Mathematics and Mechanics
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ru.edu.usu.cs.bubbles.controllers;

import ru.edu.usu.cs.bubbles.engine.GameEntity;
import ru.edu.usu.cs.bubbles.utils.TtlOut;
import android.util.Log;

public class DissapearsController extends EntityController {
	private int currentTTL = 0;
	/**
	 * Множитель для выставления прозрачности. Характеризует скорость изменения
	 * прозрачности.<BR>
	 * Нельзя выставлять 0!<BR>
	 * При увилечении -уменьшается скорость выцветания, и уменьшается время 100%
	 * непрозрачности
	 */
	private final int dissapearsMult = 10;
	private final int maxValueTransparent = 255;
	private String TAG = "DissapearsController";

	public DissapearsController(GameEntity entity, int TTL) {
		if (TTL < 0) {
			Log.e(TAG, "not correct TTL " + TTL + " for dissapears controller");
		}
		this.entity = entity; 
		currentTTL = TTL;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ru.edu.usu.cs.bubbles.controllers.EntityController#processStep()
	 */
	@Override
	public void processStep() throws TtlOut {
		if (currentTTL <= 0) {
			// отсюда не можем удалить объект - нет ссылки на GameWorld
			throw new TtlOut();
		}
		currentTTL--;
		entity.representation.setTransparent(Math.min(maxValueTransparent
				* currentTTL / dissapearsMult, maxValueTransparent));

	}

}
